home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / ck5a189s / ckuus6.c < prev    next >
C/C++ Source or Header  |  1993-06-29  |  55KB  |  1,921 lines

  1. #ifndef NOICP
  2.  
  3. /*  C K U U S 6 --  "User Interface" for Unix Kermit (Part 6)  */
  4.  
  5. /*
  6.   Author: Frank da Cruz (fdc@columbia.edu, FDCCU@CUVMA.BITNET),
  7.   Columbia University Academic Information Systems, New York City.
  8.  
  9.   Copyright (C) 1985, 1993, Trustees of Columbia University in the City of New
  10.   York.  The C-Kermit software may not be, in whole or in part, licensed or
  11.   sold for profit as a software product itself, nor may it be included in or
  12.   distributed with commercial products or otherwise distributed by commercial
  13.   concerns to their clients or customers without written permission of the
  14.   Office of Kermit Development and Distribution, Columbia University.  This
  15.   copyright notice must not be removed, altered, or obscured.
  16. */
  17.  
  18. /* Includes */
  19.  
  20. #include "ckcdeb.h"
  21. #include "ckcasc.h"
  22. #include "ckcker.h"
  23. #include "ckuusr.h"
  24. #include "ckcxla.h"
  25. #include "ckcnet.h"            /* Network symbols */
  26.  
  27. #ifdef datageneral
  28. #define fgets(stringbuf,max,fd) dg_fgets(stringbuf,max,fd)
  29. #endif /* datageneral */
  30.  
  31. #ifdef MAC                /* internal MAC file routines */
  32. #define feof mac_feof
  33. #define rewind mac_rewind
  34. #define fgets mac_fgets
  35. #define fopen mac_fopen
  36. #define fclose mac_fclose
  37.  
  38. int mac_feof();
  39. void mac_rewind();
  40. char *mac_fgets();
  41. FILE *mac_fopen();
  42. int mac_fclose();
  43. #endif /* MAC */
  44.  
  45. /* External Kermit Variables, see ckmain.c for description. */
  46.  
  47. extern int size, rpsiz, urpsiz, local, stdinf, sndsrc, xitsta,
  48.   displa, binary, parity, escape, xargc, flow,
  49.   turn, duplex, nfils, ckxech, pktlog, seslog, tralog, stdouf,
  50.   turnch, dfloc, keep, maxrps, warn, cnflg, tlevel, pflag, msgflg,
  51.   mdmtyp, zincnt, fblksiz, frecl, frecfm, atcapr, atdiso, verwho, quiet;
  52. extern int repars, techo;
  53.  
  54. extern long vernum, speed;
  55. extern char *versio, *protv, *ckxv, *ckzv, *fnsv, *connv, *dftty, *cmdv;
  56. extern char *dialv, *loginv, *for_def[], *whil_def[], *xif_def[];
  57. extern char *ckxsys, *ckzsys, *cmarg, *cmarg2, **xargv;
  58. extern char *DIRCMD, *PWDCMD, *DELCMD, *WHOCMD, ttname[], filnam[];
  59. extern CHAR sstate;
  60. extern char *zinptr;
  61.  
  62. #ifndef NOMSEND                /* Multiple SEND */
  63. extern char *msfiles[];
  64. #endif /* NOMSEND */
  65. extern char fspec[];            /* Most recent filespec */
  66.  
  67. /* Declarations from cmd package */
  68.  
  69. #ifdef DCMDBUF
  70. extern char *cmdbuf, *atmbuf;        /* Command buffers */
  71. #else
  72. extern char cmdbuf[], atmbuf[];        /* Command buffers */
  73. #endif /* DCMDBUF */
  74.  
  75. #ifndef NOSPL
  76. extern struct mtab *mactab;
  77. extern int nmac;
  78. #endif /* NOSPL */
  79.  
  80. /* Declarations from ck?fio.c module */
  81.  
  82. extern int backgrd, bgset;        /* Kermit executing in background */
  83.  
  84. #ifdef COMMENT
  85. /*
  86.   These must be on stack!
  87. */
  88. #ifndef NOSPL
  89. extern char vnambuf[];            /* Buffer for variable names */
  90. extern char *vnp;            /* Pointer to same */
  91. #endif /* NOSPL */
  92. #endif /* COMMENT */
  93.  
  94. extern char psave[];            /* For saving & restoring prompt */
  95. extern char *tp;            /* Temporary buffer */
  96.  
  97. /* Keyword tables specific to this module */
  98.  
  99. /* Modem signal table */
  100.  
  101. struct keytab mstab[] = {
  102. #ifdef COMMENT
  103. /* The forms preceded by backslash are for MS-DOS Kermit compatibility. */
  104. /* But... \dsr doesn't work because \d = decimal constant introducer */
  105.     "\\cd",  BM_DCD, CM_INV,        /* Carrier Detect */
  106.     "\\cts", BM_CTS, CM_INV,        /* Clear To Send  */
  107.     "\\dsr", BM_DSR, CM_INV,        /* Data Set Ready */
  108.     "\\ri",  BM_RNG, CM_INV,        /* Ring Indicator */
  109. #endif /* COMMENT */
  110.     "cd",    BM_DCD, 0,            /* Carrier Detect */
  111.     "cts",   BM_CTS, 0,            /* Clear To Send  */
  112.     "dsr",   BM_DSR, 0,            /* Data Set Ready */
  113.     "ri",    BM_RNG, 0            /* Ring Indicator */
  114. };
  115. int nms = (sizeof(mstab) / sizeof(struct keytab));
  116.  
  117. #ifndef NOSPL
  118. struct keytab opntab[] = {
  119. #ifndef NOPUSH
  120.     "!read",  XYFZ_Y, 0,
  121.     "!write", XYFZ_X, 0,
  122. #endif /* NOPUSH */
  123.     "append", XYFZ_A, 0,
  124.     "read",   XYFZ_O, 0,
  125.     "write",  XYFZ_N, 0
  126. };
  127. int nopn = (sizeof(opntab) / sizeof(struct keytab));
  128.  
  129. struct keytab iftab[] = {        /* IF commands */
  130.     "<",          XXIFLT, 0,
  131.     "=",          XXIFAE, 0,
  132.     ">",          XXIFGT, 0,
  133.     "background", XXIFBG, 0,
  134.     "count",      XXIFCO, 0,
  135.     "defined",    XXIFDE, 0,
  136. #ifdef COMMENT
  137.     "eof",        XXIFEO, 0,
  138. #endif /* COMMENT */
  139.     "equal",      XXIFEQ, 0,
  140.     "error",      XXIFFA, CM_INV,
  141.     "exist",      XXIFEX, 0,
  142.     "failure",    XXIFFA, 0,
  143.     "foreground", XXIFFG, 0,
  144.     "llt",        XXIFLL, 0,
  145.     "lgt",        XXIFLG, 0,
  146.     "not",        XXIFNO, 0,
  147.     "numeric",    XXIFNU, 0,
  148.     "success",    XXIFSU, 0
  149. };
  150. int nif = (sizeof(iftab) / sizeof(struct keytab));
  151. #endif /* NOSPL */
  152.  
  153. /* Variables and symbols local to this module */
  154.  
  155. #ifndef NODIAL 
  156. char *dialnum = (char *)0;        /* Remember DIAL number for REDIAL */
  157. extern char * dialdir;            /* Dial directory file name */
  158. extern FILE * dialfd;            /* Dial directory file descriptor */
  159. #endif /* NODIAL */
  160.  
  161. #ifndef NOSPL
  162. int ifc,                /* IF case */
  163.     not = 0,                /* Flag for IF NOT */
  164.     ifargs;                /* Count of IF condition words */
  165. char ifcond[100];            /* IF condition text */
  166. char *ifcp;                /* Pointer to IF condition text */
  167. #ifdef DCMDBUF
  168. extern int *ifcmd, *count, *iftest, *intime, *inpcas, *takerr, *merror;
  169. #else
  170. extern int ifcmd[];            /* Last command was IF */
  171. extern int iftest[];            /* Last IF was true */
  172. extern int count[];            /* For IF COUNT, one for each cmdlvl */
  173. extern int intime[];
  174. extern int inpcas[];
  175. extern int takerr[];
  176. extern int merror[];
  177. #endif /* DCMDBUF */
  178. #else
  179. extern int takerr[];
  180. #endif /* NOSPL */
  181.  
  182. #ifdef DCMDBUF
  183. extern char *line;            /* Character buffer for anything */
  184. extern char *tmpbuf;
  185. #else
  186. extern char line[], tmpbuf[];
  187. #endif /* DCMDBUF */
  188. extern char *lp;            /* Pointer to line buffer */
  189.  
  190. int cwdf = 0;                /* CWD has been done */
  191.  
  192. extern int en_cwd, en_del, en_dir, en_fin, /* Flags for ENABLE/DISABLE */
  193.    en_get, en_hos, en_sen, en_set, en_spa, en_typ, en_who, en_bye;
  194.  
  195. extern FILE *tfile[];            /* File pointers for TAKE command */
  196. extern char *tfnam[];            /* Names of TAKE files */
  197.  
  198. extern int success;            /* Command success/failure flag */
  199.  
  200. #ifndef NOSPL
  201. extern int maclvl;            /* Macro to execute */
  202. extern char *macx[];            /* Index of current macro */
  203. extern char *mrval[];            /* Macro return value */
  204. extern char *macp[];            /* Pointer to macro */
  205. extern int macargc[];            /* ARGC from macro invocation */
  206.  
  207. extern char *m_arg[MACLEVEL][NARGS];    /* Stack of macro arguments */
  208. extern char *g_var[];            /* Global variables %a, %b, etc */
  209.  
  210. #ifdef DCMDBUF
  211. extern struct cmdptr *cmdstk;        /* The command stack itself */
  212. #else
  213. extern struct cmdptr cmdstk[];        /* The command stack itself */
  214. #endif /* DCMDBUF */
  215. extern int cmdlvl;            /* Current position in command stack */
  216. #endif /* NOSPL */
  217.  
  218. #define xsystem(s) zsyscmd(s)
  219.  
  220. static int x, y, z = 0;
  221. static char *s, *p;
  222.  
  223. /*  X X S T R C M P  --  Caseless string comparison  */
  224. /*
  225.   Call with pointers to the two strings, s1 and s2, and a length, n.
  226.   Compares up to n characters of the two strings and returns:
  227.     1 if s1 > t1
  228.     0 if s1 = s2
  229.    -1 if s1 < t1
  230. */
  231. int
  232. xxstrcmp(s1,s2,n) char *s1, *s2; int n; { /* Caseless string comparison. */
  233.     char t1, t2;            
  234.  
  235.     if (!s1) s1 = "";            /* Watch out for null pointers. */
  236.     if (!s2) s2 = "";
  237.     while (n--) {
  238.     t1 = *s1++;            /* Get next character from each. */
  239.     if (isupper(t1)) t1 = tolower(t1);
  240.     t2 = *s2++;
  241.     if (isupper(t2)) t2 = tolower(t2);
  242.     if (t1 < t2) return(-1);    /* s1 < s2 */
  243.     if (t1 > t2) return(1);        /* s1 > s2 */
  244.     }
  245.     return(0);                /* They're equal */
  246. }
  247.  
  248. #ifndef NOSPL
  249.  
  250. /* Do the ASK, ASKQ, GETOK, and READ commands */
  251.  
  252. #ifndef NOFRILLS
  253.    extern struct keytab yesno[];
  254.    extern int nyesno;
  255. #endif /* NOFRILLS */
  256.  
  257. int
  258. doask(cx) int cx; {
  259.  
  260.     if (cx != XXGOK) {            /* Get variable name */
  261.     if ((y = cmfld("Variable name","",&s,NULL)) < 0) {
  262.         if (y == -3) {
  263.         printf("?Variable name required\n");
  264.         return(-9);
  265.         } else return(y);
  266.     }
  267.     strcpy(line,s);            /* Make a copy. */
  268.     lp = line;
  269.     if ((y = parsevar(s,&x,&z)) < 0)  /* Check to make sure it's a */
  270.       return(y);              /* variable name. */
  271.     }
  272.     if (cx == XXREA) {            /* READ command */
  273.     if ((y = cmcfm()) < 0)        /* Get confirmation */
  274.       return(y);
  275.     if (chkfn(ZRFILE) < 1) {    /* File open? */
  276.         printf("?Read file not open\n");
  277.         return(0);
  278.     }
  279.     s = line+VNAML+1;        /* Where to read into. */
  280.     y = zsinl(ZRFILE, s, LINBUFSIZ - VNAML - 1); /* Read a line. */
  281.     debug(F111,"read zsinl",s,y);
  282.     if (y < 0) {            /* On EOF or other error, */
  283.         zclose(ZRFILE);        /* close the file, */
  284.         delmac(lp);            /* delete the variable, */
  285.         return(success = 0);    /* and return failure. */
  286.     } else {            /* Read was OK. */
  287.         success = (addmac(lp,s) < 0 ? 0 : 1); /* Define the variable */
  288.             debug(F111,"read addmac",lp,success);
  289.         return(success);        /* Return success. */
  290.     }
  291.     }
  292.  
  293.     /* ASK, ASKQ, or GETOK */
  294.  
  295.     if ((y = cmtxt("Prompt, enclose in { braces } to preserve\n\
  296. leading and trailing spaces, precede question mark with backslash (\\).",
  297.            cx == XXGOK ? "{ Yes or no? }" : "",
  298.            &p,xxstring)) < 0) return(y);
  299.  
  300. #ifdef VMS
  301. /*
  302.   In VMS, whenever a TAKE file or macro is active, we had to restore the 
  303.   original console modes or else Ctrl-C/Ctrl-Y would not work.  But here we
  304.   go interactive again, so we have to temporarily put them back.
  305. */
  306.     if (cmdlvl > 0)
  307.       concb((char)escape);
  308. #endif /* VMS */
  309.       
  310.     cmsavp(psave,80);            /* Save old prompt */
  311.     if (*p == '{') {            /* New prompt enclosed in braces? */
  312.     x = (int)strlen(p) - 1;        /* Yes, strip them. */
  313.     if (p[x] == '}') {
  314.         p[x] = NUL;
  315.         p++;
  316.     }
  317.     }
  318.     cmsetp(p);                /* Make new prompt */
  319.     if (cx == XXASKQ) {            /* For ASKQ, */
  320.     concb((char)escape);        /* put console in cbreak mode */
  321.     cmini(0);            /* and no-echo mode. */
  322.     } else {                /* For others, regular echoing. */
  323.     cmini(ckxech);
  324.     }
  325.     x = -1;                /* This means to reparse. */
  326. reprompt:
  327.     if (pflag) prompt(xxstring);    /* Issue prompt. */
  328.     if (cx == XXGOK) {
  329. #ifndef NOFRILLS
  330.     x = cmkey(yesno,nyesno,"","",xxstring);    /* GETOK uses keyword table */
  331.     if (x < 0) {            /* Parse error */
  332.         if (x == -3) {        /* No answer? */
  333.         printf("Please respond Yes or No\n"); /* Make them answer */
  334.         cmini(ckxech);
  335.         }
  336.         goto reprompt;
  337.     }
  338.     if ((y = cmcfm()) < 0)        /* Get confirmation */
  339.       goto reprompt;
  340.     cmsetp(psave);            /* Restore prompt */
  341. #ifdef VMS
  342.     if (cmdlvl > 0)            /* In VMS and not at top level, */
  343.       conres();            /*  restore console again. */
  344. #endif /* VMS */
  345.     return(x);            /* Return success or failure */
  346. #else /* NOFRILLS */
  347.     ;
  348. #endif /* NOFRILLS */
  349.     } else {                /* ASK or ASKQ */
  350.     while (x == -1) {        /* Prompt till they answer */
  351.         x = cmtxt("Please respond.\n\
  352.  Type \\? to include a question mark in your response.","",&s,NULL);
  353.         debug(F111," cmtxt",s,x);
  354.     }
  355.     if (cx == XXASKQ)        /* ASKQ must echo CRLF here */
  356.       printf("\r\n");
  357.     if (x < 0) {            /* If cmtxt parse error, */
  358.         cmsetp(psave);        /* restore original prompt */
  359. #ifdef VMS
  360.         if (cmdlvl > 0)        /* In VMS and not at top level, */
  361.           conres();            /*  restore console again. */
  362. #endif /* VMS */
  363.         return(x);            /* and return cmtxt's error code. */
  364.     }
  365.     if (*s == NUL) {        /* If user typed a bare CR, */
  366.         cmsetp(psave);        /* Restore old prompt, */
  367.         delmac(lp);            /* delete variable if it exists, */
  368. #ifdef VMS
  369.         if (cmdlvl > 0)        /* In VMS and not at top level, */
  370.           conres();            /*  restore console again. */
  371. #endif /* VMS */
  372.         return(success = 1);    /* and return. */
  373.     }
  374.     y = addmac(lp,s);        /* Add it to the macro table. */
  375.     debug(F111,"ask addmac",lp,y);
  376.     cmsetp(psave);            /* Restore old prompt. */
  377. #ifdef VMS
  378.         if (cmdlvl > 0)        /* In VMS and not at top level, */
  379.           conres();            /*  restore console again. */
  380. #endif /* VMS */
  381.     return(success = y < 0 ? 0 : 1);
  382.     }
  383. }
  384. #endif /* NOSPL */
  385.  
  386. #ifndef NOSPL
  387. int
  388. doincr(cx) int cx; {            /* INCREMENT, DECREMENT */
  389.     char vnambuf[VNAML];        /* Buffer for variable names */
  390.  
  391.     if ((y = cmfld("Variable name","",&s,NULL)) < 0) {
  392.     if (y == -3) {
  393.         printf("?Variable name required\n");
  394.         return(-9);
  395.     } else return(y);
  396.     }
  397.     if (*s != CMDQ) {
  398.         *vnambuf = CMDQ;
  399.     strncpy(vnambuf+1,s,VNAML-1);
  400.     } else strncpy(vnambuf,s,VNAML);
  401.  
  402.     if ((y = parsevar(vnambuf,&x,&z)) < 0)
  403.       return(y);
  404.  
  405.     if ((y = cmnum("by amount","1",10,&x,xxstring)) < 0) return(y);
  406.     if ((y = cmcfm()) < 0) return(y);
  407.  
  408.     z = (cx == XXINC ? 1 : 0);        /* Increment or decrement? */
  409.  
  410.     if (incvar(vnambuf,x,z,&y) < 0) {
  411.     printf("?Variable %s not defined or not numeric\n",vnambuf);
  412.     return(success = 0);
  413.     }
  414.     return(success = 1);
  415. }
  416. #endif /* NOSPL */
  417.  
  418.  
  419. /* Do the (_)DEFINE and (_)ASSIGN commands */
  420.  
  421. #ifndef NOSPL
  422. int
  423. dodef(cx) int cx; {
  424.     char vnambuf[VNAML];        /* Buffer for variable names */
  425.     char *vnp;                /* Pointer to same */
  426.     if (cx == XXDFX || cx == XXASX) 
  427.       y = cmfld("Macro or variable name","",&s,xxstring); /* eval var name */
  428.     else 
  429.       y = cmfld("Macro or variable name","",&s,NULL);     /* don't evaluate */
  430.     if (y < 0) {
  431.     if (y == -3) {
  432.         printf("?Variable name required\n");
  433.         return(-9);
  434.     } else return(y);
  435.     }
  436.     debug(F111,"dodef success",s,success);
  437.     strcpy(vnambuf,s);
  438.     vnp = vnambuf;
  439.     if (vnambuf[0] == CMDQ && (vnambuf[1] == '%' || vnambuf[1] == '&')) vnp++;
  440.     if (*vnp == '%' || *vnp == '&') {
  441.     if ((y = parsevar(vnp,&x,&z)) < 0) return(y);
  442.     debug(F101,"dodef","",x);
  443.     if (y == 1) {            /* Simple variable */
  444.         if ((y = cmtxt("Definition of variable","",&s,NULL)) < 0)
  445.           return(y);
  446.         debug(F110,"xxdef var name",vnp,0);
  447.         debug(F110,"xxdef var def",s,0);
  448.     } else if (y == 2) {        /* Array element */
  449.         if ((y = arraynam(s,&x,&z)) < 0) return(y);
  450.         if (x == 96) {
  451.         printf("?Argument vector array is read-only\n");
  452.         return(-9);
  453.         }
  454.         if (chkarray(x,z) < 0) return(-2);
  455.         if ((y = cmtxt("Definition of array element","",&s,NULL)) < 0)
  456.           return(y);
  457.         debug(F110,"xxdef array ref",vnp,0);
  458.         debug(F110,"xxdef array def",s,0);
  459.     }
  460.     } else {                /* Macro */
  461.     if ((y = cmtxt("Definition of macro","",&s,NULL)) < 0) return(y);
  462.     debug(F110,"xxdef macro name",vnp,0);
  463.     debug(F110,"xxdef macro def",s,0);
  464.     if (*s == '{') {        /* Allow macro def to be bracketed. */
  465.         s++;            /* If it is, remove the brackets. */
  466.         y = (int)strlen(s);        /* FOR command depends on this! */
  467.         if (y > 0 && s[y-1] == '}') s[y-1] = NUL;
  468.     }
  469.     }
  470.     if (*s == NUL) {            /* No arg given, undefine */
  471.     delmac(vnp);            /* silently... */
  472.     return(success = 1);        /* even if it doesn't exist... */
  473.     } 
  474.  
  475.     /* Defining a new macro or variable */
  476.  
  477.     if (cx == XXASS || cx == XXASX) {    /* ASSIGN rather than DEFINE? */
  478.     int t;
  479.     t = LINBUFSIZ-1;
  480.     lp = line;            /* If so, expand its value now */
  481.     xxstring(s,&lp,&t);
  482.     s = line;
  483.     }
  484.     debug(F111,"calling addmac",s,(int)strlen(s));
  485.  
  486.     y = addmac(vnp,s);            /* Add it to the appropriate table. */
  487.     if (y < 0) {
  488.     printf("?%s failed\n",(cx == XXASS || cx == XXASX) ?
  489.            "ASSIGN" : "DEFINE");
  490.     return(success = 0);
  491.     } else if (cx == XXASX || cx == XXDFX) /* For _ASG or _DEF, */
  492.       return(1);               /* don't change success variable */
  493.     else
  494.       return(success = 1);
  495. }
  496. #endif /* NOSPL */
  497.  
  498.  
  499. #ifndef NODIAL
  500. extern struct keytab partab[];
  501. /*
  502.    L U D I A L  --  Lookup up dialing directory entry.
  503.   
  504.    Call with string to look up and file descriptor of open dialing directory
  505.    file.  On success, returns pointer to phone number and sets speed
  506.    and parity according to the directory entry.  On failure, returns the NULL
  507.    pointer.
  508. */
  509. char *
  510. ludial(s,f) char *s; FILE *f; {
  511.     int n, n1, n2, i, t;        /* Workers */
  512.     long xspeed = -1L, x2;        /* Speed to set from directory entry */
  513.     int xparity = -1;            /* Parity to set ...*/
  514.     char *info[5];            /* Array of words from entry */
  515.  
  516.     if (!s || !f) return(NULL);        /* Validate arguments */
  517.     if ((n1 = strlen(s)) < 1)
  518.       return(NULL);
  519. /*
  520.   We make one or two passes.  The first pass searches for an exact match.
  521.   If it fails, the second pass searches for the first entry of which the
  522.   search string is an abbreviation.  Of course this could be done in one
  523.   pass, but it was safer to add a couple lines for the for-loop than to
  524.   totally rearrange the code at the last minute.  (Edit 186)
  525. */
  526.     for (i = 0; i < 2; i++) {        /* Do this twice */
  527.     debug(F101,"ludial pass","",i+1);
  528.     rewind(f);            /* Go to beginning of directory file */
  529.     while (1) {
  530.         if (fgets(line,LINBUFSIZ,f) == NULL) { /* Read a line */
  531.         if (i == 0)        /* EOF */
  532.           break;        /* If first pass, start second pass */
  533.         if (!backgrd && !quiet)    /* If second pass, give message */
  534.           printf(" %s not in %s\n",s,dialdir);
  535.         debug(F110,"ludial fails",s,0);
  536.         return(NULL);
  537.         }
  538.         n = strlen(line);        /* Strip terminator(s) */
  539.         while ((n > 0) && (line[n-1] < '!'))
  540.           line[--n] = NUL;
  541.         debug(F111,"ludial",line,n);
  542.  
  543.         info[0] = NULL; info[1] = NULL; info[2] = NULL;
  544.         info[3] = NULL; info[4] = NULL;
  545.  
  546.         xwords(line,4,info);    /* Get the words. */
  547.         if (info[1]) {        /* First word. */
  548.         if ((n2 = (int) strlen(info[1])) < 1) /* Its length */
  549.           continue;        /* If no first word, keep looking. */
  550.  
  551.         if (n2 < n1)        /* If directory entry name shorter */
  552.           continue;        /* than search name, then no match. */
  553.         if (i == 0 && n2 != n1)    /* Require exact match on first pass */
  554.           continue;
  555.         if (xxstrcmp(s,info[1],n1)) /* Caseless string comparison */
  556.           continue;        /* up to length of search name */
  557.         if (!backgrd && !quiet)
  558.           printf(" From dialing directory %s: %s=%s\n",
  559.              dialdir,info[1],info[2]);
  560.         if (info[3]) {        /* Third word = speed */
  561.             if (*info[3] != '=') { /* "=" means don't change it */
  562.             xspeed = atol(info[3]);
  563.             x2 = xspeed / 10L;
  564.             if (x2 > 0) {
  565.                 if (ttsspd((int) x2) < 0)
  566.                   printf("\n Can't set speed to %s\n",info[3]);
  567.                 else 
  568.                   speed = xspeed;
  569.             }
  570.             }
  571.         }
  572.         if (info[4]) {        /* 4th word = parity */
  573.             if (*info[4] != '=') { /* "=" means don't change it */
  574.             if ((xparity = lookup(partab,info[4],5,&t)) > -1)
  575.               parity = xparity;
  576.             }
  577.         }
  578.         return(info[2]);    /* Return 2nd word = phone number */
  579.         }
  580.     }
  581.     }
  582.     return(NULL);            /* Failure */
  583. }
  584.  
  585. int
  586. dodial(cx) int cx; {            /* DIAL or REDIAL */
  587.     if (cx == XXRED) {            /* REDIAL or... */
  588.     if ((y = cmcfm()) < 0) return(y);
  589.     if (dialnum) {
  590.         s = dialnum;
  591.     } else {
  592.         printf("?No DIAL command given yet\n");
  593.         return(-9);
  594.     }
  595.     } else if (cx == XXDIAL) {        /* DIAL command */
  596.     char *s2;
  597.     if (dialdir && *dialdir)
  598.       s2 = "Number to dial or entry from dial directory";
  599.     else
  600.       s2 = "Number to dial";
  601.     if ((x = cmtxt(s2,"",&s,xxstring)) < 0)
  602.       return(x);
  603.     if (s == NULL || (int)strlen(s) == 0) {
  604.         printf("?You must specify a number to dial\n");
  605.         return(-9);
  606.     }
  607.     if (dialfd) {            /* Have dialing directory? */
  608.         if (s2 = ludial(s,dialfd))    /* Look up in dialing directory */
  609.           s = s2;            /* Make substitution if found */
  610.     }
  611.     if (dialnum) free(dialnum);    /* Make copy for REDIAL */
  612.     dialnum = malloc((int)strlen(s) + 1);
  613.     if (dialnum) strcpy(dialnum,s);
  614.     } else return(-2);
  615. #ifdef VMS
  616.     conres();                /* So Ctrl-C/Y will work */
  617. #endif /* VMS */
  618.     success = ckdial(s);        /* Try to dial */
  619. #ifdef OS2
  620.     ttres();
  621. #endif /* OS2 */
  622. #ifdef VMS
  623.     concb((char)escape);        /* Back to command parsing mode */
  624. #endif /* VMS */
  625.     return(success);
  626. }
  627. #endif /* NODIAL */
  628.  
  629. #ifndef MAC
  630. int                    /* Do the DIRECTORY command */
  631. dodir() {
  632.     char *dc;
  633. #ifdef VMS
  634.     if ((x = cmtxt("Directory/file specification","",&s,xxstring)) < 0)
  635.       return(x);
  636.     /* now do this the same as a shell command - helps with LAT  */
  637.     conres();                /* make console normal */
  638.     lp = line;
  639.     if (!(dc = getenv("CK_DIR"))) dc = DIRCMD;
  640.     sprintf(lp,"%s %s",dc,s);
  641.     debug(F110,"Directory string: ", line, 0);
  642.     xsystem(lp);
  643.     return(success = 0);
  644. #else
  645. #ifdef AMIGA
  646.     if ((x = cmtxt("Directory/file specification","",&s,xxstring)) < 0)
  647.       return(x);
  648. #else
  649. #ifdef datageneral
  650.     if ((x = cmtxt("Directory/file specification","+",&s,xxstring)) < 0)
  651.       return(x);
  652. #else /* General Case */
  653.     if ((x = cmdir("Directory/file specification","",&s,xxstring)) < 0)
  654.       if (x != -3) return(x);
  655.     strncpy(tmpbuf,s,TMPBUFSIZ);
  656.     if ((y = cmcfm()) < 0) return(y);
  657.     s = tmpbuf;
  658. #endif /* datageneral */
  659. #endif /* AMIGA */
  660.     /* General case again */
  661.     lp = line;
  662.     if (!(dc = getenv("CK_DIR"))) dc = DIRCMD;
  663.     sprintf(lp,"%s %s",dc,s);
  664.     xsystem(line);
  665.     return(success = 1);        /* who cares... */
  666. #endif /* VMS */
  667. }
  668. #endif /* MAC */
  669.  
  670. #ifndef NOFRILLS
  671. /* Do the ENABLE and DISABLE commands */
  672.  
  673. int
  674. doenable(cx,x) int cx, x; {
  675.     y = ((cx == XXENA) ? 1 : 0);
  676.     switch (x) {
  677.       case EN_ALL:
  678.     en_cwd = en_del = en_dir = en_fin = en_get = y;
  679.     en_sen = en_set = en_spa = en_typ = en_who = y;
  680. #ifndef datageneral
  681.         en_bye = y;
  682. #endif /* datageneral */
  683.  
  684. #ifndef NOPUSH
  685.     en_hos = y;
  686. #endif /* NOPUSH */
  687.     break;
  688.       case EN_BYE:
  689. #ifndef datageneral
  690. /*
  691.   In Data General AOS/VS Kermit can't log out its superior process.
  692. */
  693.         en_bye = y;
  694. #endif /* datageneral */
  695.     break;
  696.       case EN_CWD:
  697.     en_cwd = y;
  698.     break;
  699.       case EN_DEL:
  700.     en_del = y;
  701.     break;
  702.       case EN_DIR:
  703.     en_dir = y;
  704.     break;
  705.       case EN_FIN:
  706.     en_fin = y;
  707.     break;
  708.       case EN_GET:
  709.     en_get = y;
  710.     break;
  711. #ifndef NOPUSH
  712.       case EN_HOS:
  713.     en_hos = y;
  714.     break;
  715. #endif /* NOPUSH */
  716.       case EN_SEN:
  717.     en_sen = y;
  718.     break;
  719.       case EN_SET:
  720.     en_set = y;
  721.     break;
  722.       case EN_SPA:
  723.     en_spa = y;
  724.     break;
  725.       case EN_TYP:
  726.     en_typ = y;
  727.     break;
  728.       case EN_WHO:
  729.     en_who = y;
  730.     break;
  731.       default:
  732.     return(-2);
  733.     }
  734.     return(1);
  735. }
  736. #endif /* NOFRILLS */
  737.  
  738. #ifndef NOFRILLS
  739. int
  740. dodel() {                /* DELETE */
  741.     long zl;
  742.     if ((x = cmifi("File(s) to delete","",&s,&y,xxstring)) < 0) {
  743.     if (x == -3) {
  744.         printf("?A file specification is required\n");
  745.         return(-9);
  746.     } else return(x);
  747.     }
  748. #ifdef MAC
  749.     strcpy(line,s);
  750. #else
  751.     strncpy(tmpbuf,s,TMPBUFSIZ);    /* Make a safe copy of the name. */
  752.     debug(F110,"xxdel tmpbuf",s,0);
  753.     sprintf(line,"%s %s",DELCMD,s);    /* Construct the system command. */
  754. #endif /* MAC */
  755.     debug(F110,"xxdel line",line,0);
  756.     if ((y = cmcfm()) < 0) return(y);    /* Confirm the user's command. */
  757. #ifdef VMS
  758.     conres();
  759. #endif /* VMS */
  760. #ifdef MAC
  761.     s = line;
  762.     success = (zdelet(line) == 0);
  763. #else
  764.     s = tmpbuf;
  765.     xsystem(line);            /* Let the system do it. */
  766.     zl = zchki(tmpbuf);
  767.     success = (zl == -1L);
  768. #endif /* MAC */
  769.     if (msgflg)
  770.       printf("%s - %sdeleted\n",s, success ? "" : "not ");
  771.     return(success);
  772. }
  773. #endif /* NOFRILLS */
  774.  
  775. #ifndef NOSPL                /* The ELSE command */
  776. int
  777. doelse() {
  778.     if (!ifcmd[cmdlvl]) {
  779.     printf("?ELSE doesn't follow IF\n");
  780.     return(-2);
  781.     }
  782. #ifdef COMMENT
  783. /*
  784.   Wrong.  This prevents IF..ELSE IF...ELSE IF...ELSE IF...ELSE...
  785.   from working.
  786. */
  787.     ifcmd[cmdlvl] = 0;
  788. #endif /* COMMENT */
  789.     if (!iftest[cmdlvl]) {        /* If IF was false do ELSE part */
  790.     if (maclvl > -1) {        /* In macro, */
  791.         pushcmd();            /* save rest of command. */
  792.     } else if (tlevel > -1) {    /* In take file, */
  793.         pushcmd();            /* save rest of command. */
  794.     } else {            /* If interactive, */
  795.         cmini(ckxech);        /* just start a new command */
  796.         printf("\n");        /* (like in MS-DOS Kermit) */
  797.         if (pflag) prompt(xxstring);
  798.     }
  799.     } else {                /* Condition is false */
  800.     if ((y = cmtxt("command to be ignored","",&s,NULL)) < 0)
  801.       return(y);            /* Gobble up rest of line */
  802.     }
  803.     return(0);
  804. }
  805. #endif /* NOSPL */
  806.  
  807. #ifndef NOSPL
  808. int
  809. dofor() {                /* The FOR command. */
  810.     int fx, fy, fz;            /* loop variables */
  811.     char *ap;                /* macro argument pointer */
  812.  
  813.     if ((y = cmfld("Variable name","",&s,NULL)) < 0) { /* Get variable name */
  814.     if (y == -3) {
  815.         printf("?Variable name required\n");
  816.         return(-9);
  817.     } else return(y);
  818.     }
  819.     if ((y = parsevar(s,&x,&z)) < 0)    /* Check it. */
  820.       return(y);
  821.  
  822.     lp = line;                /* Build a copy of the command */
  823.     strcpy(lp,"_forx ");
  824.     lp += (int)strlen(line);        /* "_for" macro. */
  825.     ap = lp;                /* Save pointer to macro args. */
  826.  
  827.     if (*s == CMDQ) s++;        /* Skip past backslash if any. */
  828.     while (*lp++ = *s++) ;        /* copy it */
  829.     lp--; *lp++ = SP;            /* add a space */
  830.  
  831.     if ((y = cmnum("initial value","",10,&fx,xxstring)) < 0) {
  832.     if (y == -3) return(-2);
  833.     else return(y);
  834.     }
  835.     s = atmbuf;                /* Copy the atom buffer */
  836.     if ((int)strlen(s) < 1) goto badfor;
  837.     while (*lp++ = *s++) ;        /* (what they actually typed) */
  838.     lp--; *lp++ = SP;
  839.  
  840.     if ((y = cmnum("final value","",10,&fy,xxstring)) < 0) {
  841.     if (y == -3) return(-2);
  842.     else return(y);
  843.     }
  844.     s = atmbuf;                /* Same deal */
  845.     if ((int)strlen(s) < 1) goto badfor;
  846.     while (*lp++ = *s++) ;
  847.     lp--; *lp++ = SP;
  848.  
  849.     if ((y = cmnum("increment","1",10,&fz,xxstring)) < 0) {
  850.     if (y == -3) return(-2);
  851.     else return(y);
  852.     }
  853.     sprintf(tmpbuf,"%d ",fz);
  854.     s = atmbuf;                /* same deal */
  855.     if ((int)strlen(s) < 1) goto badfor;
  856.     while (*lp++ = *s++) ;
  857.     lp--; *lp++ = SP;
  858.  
  859.     /* Insert the appropriate comparison operator */
  860.     if (fz < 0)
  861.       *lp++ = '<';
  862.     else
  863.       *lp++ = '>';
  864.     *lp++ = SP;
  865.  
  866.     if ((y = cmtxt("Command to execute","",&s,NULL)) < 0) return(y);
  867.     if ((int)strlen(s) < 1) return(-2);
  868.     
  869.     if (litcmd(&s,&lp) < 0) {
  870.     printf("?Unbalanced brackets\n");
  871.     return(0);
  872.     }
  873.     if (fz == 0) {
  874.     printf("?Zero increment not allowed\n");
  875.     return(0);
  876.     }
  877.     x = mlook(mactab,"_forx",nmac);    /* Look up FOR macro definition */
  878.     if (x < 0) {            /* Not there? */
  879.     addmmac("_forx",for_def);    /* Put it back. */
  880.     if ((x = mlook(mactab,"_forx",nmac)) < 0) { /* Look it up again. */
  881.         printf("?FOR macro definition gone!\n"); /* Shouldn't happen. */
  882.         return(success = 0);
  883.     }
  884.     }
  885.     debug(F110,"FOR command",line,0);
  886.     return(success = dodo(x,ap));    /* Execute the FOR macro. */
  887.  
  888. badfor: printf("?Incomplete FOR command\n");
  889.     return(-2);
  890. }
  891. #endif /* NOSPL */
  892.  
  893. #ifndef NOFRILLS
  894. /* Do the BUG command */
  895.  
  896. int
  897. dobug() {
  898.     printf("\n%s,%s\n Numeric: %ld",versio,ckxsys,vernum);
  899.     if (verwho) printf("-%d",verwho);
  900.     printf("\nTo report C-Kermit bugs, send e-mail to:\n");
  901.     printf(" kermit@columbia.edu (Internet)\n");
  902.     printf(" KERMIT@CUVMA (EARN/CREN/BITNET)\n");
  903.     printf(" ...!uunet!columbia.edu!kermit (Usenet)\n");
  904.     printf("Or write to:\n Kermit Development\n Columbia University\n");
  905.     printf(" 612 W 115 Street\n");
  906.     printf(" New York, NY  10025  USA\nOr call:\n +1 212 854-5126 (USA)\n\n");
  907. #ifndef NOSHOW
  908. #ifndef NOFRILLS
  909.     printf(
  910. "Before reporting problems, please use the SHOW VERSION and SHOW FEATURES\n");
  911.     printf(
  912. "commands to get detailed program version and configuration information.\n\n");
  913. #endif /* NOFRILLS */
  914. #endif /* NOSHOW */
  915.     return(1);
  916. }
  917. #endif /* NOFRILLS */
  918.  
  919. #ifndef NOSPL
  920. int
  921. dopaus(cx) int cx; {
  922.     /* Both should take not only secs but also hh:mm:ss as argument. */
  923.     if (cx == XXWAI)
  924.       y = cmnum("seconds to wait","1",10,&x,xxstring);
  925.     else if (cx == XXPAU)
  926.       y = cmnum("seconds to pause","1",10,&x,xxstring);
  927.     else
  928.       y = cmnum("milliseconds to sleep","100",10,&x,xxstring);
  929.     if (y < 0) return(y);
  930.     if (x < 0) x = 0;
  931.     switch (cx) {
  932.       case XXPAU:            /* PAUSE */
  933.       case XXMSL:            /* MSLEEP */
  934.     if ((y = cmcfm()) < 0) return(y);
  935.     break;
  936.       case XXWAI:            /* WAIT */
  937.     z = 0;                /* Modem signal mask */
  938.     while (1) {            /* Read zero or more signal names */
  939.         y = cmkey(mstab,nms,"modem signal","",xxstring);
  940.         if (y == -3) break;        /* -3 means they typed CR */
  941.         if (y < 0) return(y);    /* Other negatives are errors */
  942.         z |= y;            /* OR the bit into the signal mask */
  943.     }
  944.     break;
  945.  
  946.       default:                /* Shouldn't happen */
  947.     return(-2);
  948.     }
  949.  
  950. /* Command is entered, now do it. */
  951.  
  952.     if (cx == XXMSL) {            /* Millisecond sleep */
  953.     msleep(x);
  954.     return(success = 1);
  955.     }
  956.     while (x--) {            /* Sleep loop */
  957.     int mdmsig;
  958.     if (y = conchk()) {        /* Did they type something? */
  959.         while (y--) coninc(0);    /* Yes, gobble it up */
  960.         break;            /* And quit PAUSing or WAITing */
  961.     }
  962.     if (cx == XXWAI && z != 0) {
  963.         mdmsig = ttgmdm();
  964.         if (mdmsig < 0) return(success = 0);
  965.         if ((mdmsig & z) == z) return(success = 1);
  966.     }
  967.     sleep(1);            /* No interrupt, sleep one second */
  968.     }
  969.     if (cx == XXWAI) success = 0;
  970.     else success = (x == -1);        /* Set SUCCESS/FAILURE for PAUSE. */
  971.     return(0);
  972. }
  973. #endif /* NOSPL */
  974.  
  975.  
  976. #ifndef NOFRILLS
  977. int
  978. dorenam() {
  979.     if ((x = cmifi("File to rename","",&s,&y,xxstring)) < 0) {
  980.     if (x == -3) {
  981.         printf("?Name of existing file required\n");
  982.         return(-9);
  983.     } else return(x);
  984.     }
  985.     if (y) {                /* No wildcards allowed */
  986.     printf("\n?Please specify a single file\n");
  987.     return(-9);
  988.     }
  989.     strcpy(line,s);            /* Make a safe copy of the old name */
  990.     p = line + (int)strlen(line) + 2;    /* Place for new name */
  991.     if ((x = cmofi("New name","",&s,xxstring)) < 0) { /* Get new name */
  992.     if (x == -3) {
  993.         printf("?New name for file required\n");
  994.         return(-9);
  995.     } else return(x);
  996.     }
  997.     strcpy(p,s);            /* Make a safe copy of the new name */
  998.     if ((y = cmcfm()) < 0) return(y);
  999. #ifdef VMS
  1000.     conres();                /* Let Ctrl-C work. */
  1001. #endif /* VMS */
  1002.     return(zrename(line,p));
  1003. }
  1004. #endif /* NOFRILLS */
  1005.  
  1006.  
  1007. #ifndef NOSPL
  1008.  
  1009. /* Do the RETURN command */
  1010.  
  1011. int
  1012. doreturn(s) char *s; {
  1013.     int x; char *p;
  1014.     if (maclvl < 0) {
  1015.     printf("\n?Can't return from level %d\n",maclvl);
  1016.     return(success = 0);
  1017.     }
  1018.     lp = line;                /* Expand return value now */
  1019.     x = LINBUFSIZ-1;
  1020.     if (xxstring(s,&lp,&x) > -1) {
  1021.     s = line;
  1022.     debug(F110,"RETURN parse",s,0);
  1023.     }
  1024.     x = (int)strlen(s);            /* Is there a return value? */
  1025.     if (x > 0) {            /* Yes */
  1026.     p = malloc(x+2);        /* Allocate a place to keep it */
  1027.     if (p) {            /* Did we get a place? */
  1028.         strcpy(p, s);        /* Yes, copy the string into it. */
  1029.         mrval[maclvl] = p;        /* Make return value point to it. */
  1030.         debug(F110,"RETURN copy",mrval[maclvl],0);
  1031.     } else {            /* No, could not get space. */
  1032.         mrval[maclvl] = NULL;    /* Return null pointer. */
  1033.         x = 0;            /* Set failure return code. */
  1034.     }
  1035.     } else mrval[maclvl] = NULL;    /* Blank return code */
  1036. #undef FORRET
  1037. /*
  1038.   If we are in a FOR, WHILE, or XIF command list, also copy the return value
  1039.   two levels up.  (But this doesn't work, so forget it.)
  1040. */
  1041. #ifdef FORRET
  1042.     if (maclvl > 1) {
  1043.     if (!strncmp(m_arg[maclvl][0],"_for",4) ||
  1044.         !strncmp(m_arg[maclvl][0],"_whi",4) ||
  1045.         !strncmp(m_arg[maclvl][0],"_xif",4)) {
  1046.         mrval[maclvl-2] = p;
  1047.     }
  1048.     }
  1049. #endif /* FORRET */
  1050.     popclvl();                /* Pop command level */
  1051.  
  1052. #ifdef DEBUG
  1053.     if (mrval[maclvl+1])
  1054.       debug(F111,"&return",mrval[maclvl+1],maclvl);
  1055.     else debug(F111,"&return","NULL",maclvl);
  1056. #endif /* DEBUG */
  1057.     return(success = x ? 1 : 0);    /* Return status code */    
  1058. }
  1059. #endif /* NOSPL */
  1060.  
  1061. #ifndef NOSPL
  1062. /* Do the OPEN command */
  1063.  
  1064. int
  1065. doopen()  {                /* OPEN { append, read, write } */
  1066.     int x, y, z; char *s;
  1067.     static struct filinfo fcb;        /* (must be static) */
  1068.     if ((x = cmkey(opntab,nopn,"mode","",xxstring)) < 0) {
  1069.     if (x == -3) {
  1070.         printf("?Mode required\n");
  1071.         return(-9);
  1072.     } else return(x);
  1073.     }
  1074.     switch (x) {
  1075.       case XYFZ_O:            /* Old file (READ) */
  1076.     if (chkfn(ZRFILE) > 0) {
  1077.         printf("?Read file already open\n");
  1078.         return(-2);
  1079.     }
  1080.     if ((z = cmifi("File to read","",&s,&y,xxstring)) < 0) {
  1081.         if (z == -3) {
  1082.         printf("?Input filename required\n");
  1083.         return(-9);
  1084.         } else return(z);
  1085.     }
  1086.     if (y) {                /* No wildcards allowed */
  1087.         printf("\n?Please specify a single file\n");
  1088.         return(-2);
  1089.     }
  1090.     strcpy(line,s);
  1091.     if ((int)strlen(line) < 1) return(-2);
  1092.     if ((y = cmcfm()) < 0) return(y);
  1093.     return(success = zopeni(ZRFILE,line));
  1094.  
  1095. #ifndef MAC
  1096. #ifndef NOPUSH
  1097.       case XYFZ_Y:            /* Pipe/Process (READ) */
  1098.     if (chkfn(ZRFILE) > 0) {
  1099.         printf("?Read file already open\n");
  1100.         return(-2);
  1101.     }
  1102.         if ((y = cmtxt("System command to read from","",&s,xxstring)) < 0) {
  1103.         if (y == -3) {
  1104.         printf("?Command name required\n");
  1105.         return(-9);
  1106.         } else return(y);
  1107.     }
  1108.     strcpy(line,s);
  1109.     if ((int)strlen(line) < 1) return(-2);
  1110.     if ((y = cmcfm()) < 0) return(y);
  1111.     return(success = zxcmd(ZRFILE,line));
  1112.  
  1113.       case XYFZ_X:            /* Write to pipe */
  1114.     if (chkfn(ZWFILE) > 0) {
  1115.         printf("?Write file already open\n");
  1116.         return(-2);
  1117.     }
  1118.         if ((y = cmtxt("System command to write to","",&s,xxstring)) < 0) {
  1119.         if (y == -3) {
  1120.         printf("?Command name required\n");
  1121.         return(-9);
  1122.         } else return(y);
  1123.     }
  1124.     strcpy(line,s);
  1125.     if ((int)strlen(line) < 1) return(-2);
  1126.     if ((y = cmcfm()) < 0) return(y);
  1127.     success = zxcmd(ZWFILE,line);
  1128.     if (!success && msgflg)
  1129.       printf("Can't open process for writing: %s\n",line);
  1130.     return(success);
  1131. #endif /* NOPUSH */
  1132. #endif /* MAC */
  1133.  
  1134.       case XYFZ_N:            /* New file (WRITE) */
  1135.       case XYFZ_A:            /* (APPEND) */
  1136.     if ((z = cmofi("Name of local file to create","",&s,xxstring)) < 0) {
  1137.         if (z == -3) {
  1138.         printf("?Filename required\n");
  1139.         return(-9);
  1140.         } else return(z);
  1141.     }
  1142.     if (chkfn(ZWFILE) > 0) {
  1143.         printf("?Write/Append file already open\n");
  1144.         return(-2);
  1145.     }
  1146.         fcb.bs = fcb.cs = fcb.rl = fcb.fmt = fcb.org = fcb.cc = fcb.typ = 0;
  1147.     fcb.lblopts = 0;
  1148.     fcb.dsp = x;            /* Create or Append */
  1149.     strcpy(line,s);
  1150.     if ((int)strlen(line) < 1) return(-2);
  1151.     if ((y = cmcfm()) < 0) return(y);
  1152.     return(success = zopeno(ZWFILE,line,NULL,&fcb));
  1153.  
  1154.       default:
  1155.     printf("?Not implemented");
  1156.     return(-2);
  1157.     }
  1158. }
  1159. #endif /* NOSPL */
  1160.  
  1161. /* Finish parsing and do the GET command */
  1162.  
  1163. int
  1164. doget() {
  1165.     int x;
  1166.     char *cbp;
  1167.  
  1168.     cmarg2 = "";            /* Initialize as-name to nothing */
  1169.     x = 0;
  1170. #ifdef NOFRILLS
  1171.     if (*cmarg == NUL) {
  1172.     printf("?Remote filespec required\n");
  1173.     return(-3);
  1174.     }
  1175. #else
  1176. /*
  1177.   If remote file name omitted, get foreign and local names separately.
  1178.   But multine GET is allowed only if NOFRILLS is not defined.
  1179. */
  1180.     if (*cmarg == NUL) {
  1181.  
  1182.     if (tlevel > -1
  1183. #ifndef NOSPL
  1184.         && cmdstk[cmdlvl].src == CMD_TF
  1185. #endif /* NOSPL */
  1186.         ) {
  1187.  
  1188. /* Input is from a command file. */
  1189.  
  1190.         /* Read 2nd line of GET command */
  1191.  
  1192.         if (getnct(cmdbuf,CMDBL) < 0) {
  1193.         printf("Command file ends prematurely in multiline GET\n");
  1194.         popclvl();
  1195.         return(-9);
  1196.         }
  1197.         cmres();            /* Parse it */
  1198.         if ((x = cmtxt("Oofa","",&s,xxstring)) < 0)
  1199.           return(x);
  1200.         if (*s == '{') {        /* Strip enclosing braces */
  1201.         x = (int)strlen(s);
  1202.         if (s[x-1] == '}') {
  1203.             s[x-1] = NUL;
  1204.             s++;
  1205.         }
  1206.         }
  1207.         strcpy(line,s);        /* Make a safe copy */
  1208.         cmarg = line;        /* Point to remote filename */
  1209.         if (*cmarg == NUL) {    /* Make sure there is one */
  1210.         printf("Remote filename missing in multiline GET\n");
  1211.         return(-9);
  1212.         }
  1213.         lp = line + strlen(line) + 1; /* Place for as-name */
  1214.  
  1215.         /* And third line... */
  1216.  
  1217.         cmarg2 = "";        /* Assume no as-name */
  1218.         if (getnct(cmdbuf,CMDBL) < 0) { /* Get next line */
  1219.         popclvl();        /* There isn't one. */
  1220.         } else {            /* There is... */
  1221.         if (*cmdbuf >= ' ') {    /* Parse as output filename */
  1222.             cmres();
  1223.             if ((x = cmofi("Mupeen",cmarg,&s,xxstring)) < 0)
  1224.               return(x);
  1225.             strcpy(lp,s);    /* Make a safe copy */
  1226.             cmarg2 = lp;    /* Point as-name pointer at it */
  1227.         }
  1228.         }
  1229.             x = 0;            /* Return code OK */
  1230.  
  1231. #ifndef NOSPL
  1232. /* Reading commands from a macro definition */
  1233.  
  1234.     } else if (cmdlvl > 0 && cmdstk[cmdlvl].src == CMD_MD) {
  1235.  
  1236.         /* Read second line of GET command */
  1237.  
  1238.         cbp = cmdbuf;
  1239.         if (getncm(cbp,CMDBL) < 0) {
  1240.         printf("Macro definition ends prematurely in multiline GET\n");
  1241.         return(-9);
  1242.         }
  1243.         cmres();
  1244.         if ((x = cmtxt("Oofa","",&s,xxstring)) < 0) return(x);
  1245.         if (*s == NUL) {        /* Make sure we got something */
  1246.         printf("Remote filename missing in multiline GET\n");
  1247.         return(-9);
  1248.         }
  1249.         if (*s == '{') {        /* Strip enclosing braces */
  1250.         x = (int)strlen(s);
  1251.         if (s[x-1] == '}') {
  1252.             s[x-1] = NUL;
  1253.             s++;
  1254.         }
  1255.         }
  1256.         strcpy(line,s);        /* Copy filename to safe place */
  1257.         cmarg = line;        /* Point to it */
  1258.         x = strlen(line);        /* Get its length */
  1259.         lp = line + x + 1;        /* Where to put the next bit */
  1260.         y = LINBUFSIZ - x - 1;    /* Room left for next bit */
  1261.  
  1262.         /* And third line... */
  1263.  
  1264.         cmarg2 = "";        /* Assume no as-name */
  1265.         if (getncm(lp,y) > -1 && *lp >= ' ') { /* Read next line */
  1266.         x = strlen(lp);
  1267.         if (lp[x-1] == CR) lp[x-1] = NUL; /* Remove CR */
  1268.         cbp = cmdbuf;        /* Interpret the line */
  1269.         *cbp = NUL;        /* ... */
  1270.         y = CMDBL;        /* into the command buffer */
  1271.         xxstring(lp,&cbp,&y);
  1272.         if (*cmdbuf) {        /* If we have something */
  1273.             cmres();        /* parse it as an output filename */
  1274.             strcat(cmdbuf," ");
  1275.             if ((x = cmofi("Mupeen","",&s,NULL)) < 0)
  1276.               return(x);
  1277.             strcpy(lp,s);    /* Copy the name to safe place */
  1278.             cmarg2 = lp;    /* and make as-name pointer */
  1279.         }
  1280.         }
  1281.             x = 0;            /* Return code OK */
  1282. #endif /* NOSPL */
  1283.         } else {            /* Input is from terminal */
  1284.  
  1285.         cmsavp(psave,80);
  1286.         cmsetp(" Remote file specification: "); /* Make new one */
  1287.         cmini(ckxech);
  1288.         x = -1;
  1289.         if (pflag) prompt(xxstring);
  1290.         while (x == -1) {        /* Prompt till they answer */
  1291.             x = cmtxt("Name of remote file(s)","",&cmarg,xxstring);
  1292.         debug(F111," cmtxt",cmarg,x);
  1293.         }
  1294.         if (x < 0) {
  1295.         cmsetp(psave);
  1296.         return(x);
  1297.         }
  1298.         if (*cmarg == NUL) {     /* If user types a bare CR, */
  1299.         printf("(cancelled)\n"); /* Forget about this. */
  1300.             cmsetp(psave);        /* Restore old prompt, */
  1301.         return(0);        /* and return. */
  1302.         }
  1303.         if (*cmarg == '{') {    /* Strip enclosing braces */
  1304.         x = (int)strlen(cmarg);
  1305.         if (cmarg[x-1] == '}') {
  1306.             cmarg[x-1] = NUL;
  1307.             cmarg++;
  1308.         }
  1309.         }
  1310.         strcpy(line,cmarg);        /* Make a safe copy */
  1311.         cmarg = line;
  1312.         cmsetp(" Local name to store it under: "); /* New prompt */
  1313.         cmini(ckxech);
  1314.         x = -1;
  1315.         if (pflag) prompt(xxstring);
  1316.         while (x == -1) {        /* Again, parse till answered */
  1317.             x = cmofi("Local file name","",&cmarg2,xxstring);
  1318.         }
  1319.         if (x < 0) {        /* Parse error */
  1320.         if (x == -3) {        /* CR = cancel */
  1321.             printf("(cancelled)\n"); /* Print message */
  1322.             x = 0;        /* Avoid further messages */
  1323.         }
  1324.         cmsetp(psave);        /* Restore prompt */
  1325.         return(x);
  1326.         }        
  1327.         x = -1;            /* Get confirmation. */
  1328.         while (x == -1) x = cmcfm();
  1329.         cmsetp(psave);        /* Restore old prompt. */
  1330.         }
  1331.     }
  1332. #endif /* NOFRILLS */
  1333.     if (x == 0) {            /* Good return from cmtxt or cmcfm, */
  1334.     debug(F110,"xxget cmarg",cmarg,0);
  1335.     strncpy(fspec,cmarg,FSPECL);
  1336.     debug(F111,"xxget fspec",fspec,FSPECL);
  1337.     sstate = 'r';            /* Set start state. */
  1338.     if (local) {
  1339.         displa = 1;
  1340.         ttflui();
  1341.     }
  1342.     }
  1343.     return(x);
  1344. }
  1345.  
  1346. #ifndef NOSPL
  1347.  
  1348. int
  1349. dogta(cx) int cx; {
  1350.     int i; char c; char mbuf[4]; char *p;
  1351.  
  1352.     if ((y = cmcfm()) < 0)
  1353.       return(y);
  1354.     if (cx == XXGTA)
  1355.       debug(F101,"_getargs maclvl","",maclvl);
  1356.     else if (cx == XXPTA)
  1357.       debug(F101,"_putargs maclvl","",maclvl);
  1358.     else
  1359.       return(-2);
  1360.     if (maclvl < 1)
  1361.       return(success = 0);
  1362.  
  1363.     debug(F101,"success","",success);
  1364.  
  1365.     mbuf[0] = '%'; mbuf[1] = '0'; mbuf[2] = '\0'; /* Argument name buf */
  1366.     for (i = 0; i < 10; i++) {        /* For all args */
  1367.     c = (char) i + '0';        /* Make name */
  1368.     mbuf[1] = c;            /* Insert digit */
  1369.     if (cx == XXGTA) {        /* Get arg from level-minus-2 */
  1370.         if (maclvl == 1) p = g_var[c]; /* If at level 1 use globals 0..9 */
  1371.         else p = m_arg[maclvl-2][i]; /* Otherwise they're on the stack */
  1372.         if (!p) {
  1373.         debug(F111,"_getarg p","(null pointer)",i);
  1374.         } else debug(F111,"_getarg p",p,i);
  1375.         addmac(mbuf,p);
  1376.     } else if (cx == XXPTA) {    /* Put args level+2 */
  1377. #ifndef MAC
  1378.         connoi();            /* Turn off interrupts. */
  1379. #endif /* MAC */
  1380.         maclvl -= 2;        /* This is gross.. */
  1381.         p = m_arg[maclvl+2][i];
  1382.         if (p)
  1383.           debug(F111,"_putarg m_arg[maclvl+2][i]",p,i);
  1384.         else
  1385.           debug(F111,"_putarg m_arg[maclvl+2][i]","(null pointer)",i);
  1386.         addmac(mbuf,m_arg[maclvl+2][i]);
  1387.         maclvl += 2;
  1388. #ifndef MAC
  1389.         conint(trap,stptrap);    /* Restore interrupts */
  1390. #endif /* MAC */
  1391.     } else return(success = 0);
  1392.     }
  1393.     debug(F101,"_get/putarg exit","",i);
  1394.     debug(F101,"_get/putarg exit maclvl","",maclvl);
  1395. #ifdef COMMENT
  1396. /*
  1397.   Internal commands don't change success variable if they succeed.
  1398. */
  1399.     return(success = 1);
  1400. #else
  1401.     return(1);
  1402. #endif /* COMMENT */
  1403.  
  1404. }
  1405. #endif /* NOSPL */
  1406.  
  1407.  
  1408. #ifndef NOSPL
  1409. /* Do the GOTO command */
  1410.  
  1411. int
  1412. dogoto(s) char *s; {
  1413.     int i, j, x, y;
  1414.     char tmplbl[50], *lp;
  1415.  
  1416.     debug(F101,"goto cmdlvl","",cmdlvl);
  1417.     debug(F101,"goto maclvl","",maclvl);
  1418.     debug(F101,"goto tlevel","",tlevel);
  1419.     debug(F110,"goto before conversion",s,0);
  1420.     y = (int)strlen(s);
  1421.     if (*s != ':') {            /* If the label mentioned */
  1422.     for (i = y; i > 0; i--) {    /* does not begin with a colon, */
  1423.         s[i] = s[i-1];        /* then insert one. */
  1424.     }                /* Also, convert to lowercase. */
  1425.     s[0] = ':';
  1426.     s[++y] = '\0';
  1427.     }
  1428.     debug(F111,"goto after conversion",s,y);
  1429.     if (s[1] == '.' || s[1] == SP || s[1] == NUL) {
  1430.     printf("?Bad label syntax - '%s'\n",s);
  1431.     return(success = 0);
  1432.     }
  1433.     if (cmdlvl == 0) {
  1434.     printf("?Sorry, GOTO only works in a command file or macro\n");
  1435.     return(success = 0);
  1436.     }
  1437.     while (cmdlvl > 0) {        /* Only works inside macros & files */
  1438.     if (cmdstk[cmdlvl].src == CMD_MD) { /* GOTO inside macro */
  1439.         int i, m, flag;
  1440.         char *xp, *tp;
  1441.  
  1442.         lp = macx[maclvl];
  1443.         m = (int)strlen(lp) - y + 1;
  1444.         debug(F111,"goto in macro",lp,m);
  1445.  
  1446.         flag = 1;            /* flag for valid label position */
  1447.         for (i = 0; i < m; i++,lp++) { /* search for label in macro body */
  1448.         if (*lp == ',') {    /* Really should also watch out */
  1449.             flag = 1;        /* for braces here...  Commas in */
  1450.             continue;        /* in braces are not really commas */
  1451.         }
  1452.         if (flag) {        /* If in valid label position */
  1453.             if (*lp == SP)    /* eat leading spaces */
  1454.               continue;
  1455.             if (*lp != ':') {    /* Look for label introducer */
  1456.             flag = 0;    /* this isn't it */
  1457.             continue;    /* keep looking */
  1458.             }
  1459.         }
  1460.         if (!flag)        /* We don't have a label */
  1461.           continue;        /*  so keep looking... */
  1462.         xp = lp; tp = tmplbl;    /* Copy the label from the macro */
  1463.         j = 0;            /* to make it null-terminated */
  1464.         while (*tp = *xp) {
  1465.             if (j++ > 50) break;  /* j = length of word from macro */
  1466.             if (*tp < 33 || *tp == ',')    /* Look for end of word */
  1467.               break;
  1468.             else tp++, xp++;    /* Next character */
  1469.         }
  1470.         *tp = '\0';        /* In case we stopped early */
  1471.         /* Now do caseless string comparison, using longest length */
  1472.         debug(F111,"macro GOTO label",s,y);
  1473.         debug(F111,"macro target label",tmplbl,j);
  1474.         if (!xxstrcmp(s,tmplbl,(y > j) ? y : j))
  1475.           break;
  1476.         else flag = 0;
  1477.         }
  1478.         if (i == m) {        /* didn't find the label */
  1479.         debug(F101,"goto failed at cmdlvl","",cmdlvl);
  1480.         if (!popclvl()) {    /* pop up to next higher level */
  1481.             printf("?Label '%s' not found\n",s); /* if none */
  1482.             return(0);        /* quit */
  1483.         } else continue;    /* otherwise look again */
  1484.         }
  1485.         debug(F110,"goto found macro label",lp,0);
  1486.         macp[maclvl] = lp;        /* set macro buffer pointer */
  1487.         return(1);
  1488.     } else if (cmdstk[cmdlvl].src == CMD_TF) {
  1489.         x = 0;            /* GOTO issued in take file */
  1490.         rewind(tfile[tlevel]);    /* Search file from beginning */
  1491.         while (! feof(tfile[tlevel])) {
  1492.         if (fgets(line,LINBUFSIZ,tfile[tlevel]) == NULL) /* Get line */
  1493.           break;        /* If no more, done, label not found */
  1494.         lp = line;        /* Got line */
  1495.         while (*lp == SP || *lp == HT)
  1496.           lp++;            /* Strip leading whitespace */
  1497.         if (*lp != ':') continue; /* Check for label introducer */
  1498.         tp = lp;        /* Get end of word */
  1499.         j = 0;
  1500.         while (*tp) {        /* And null-terminate it */
  1501.             if (*tp < 33) {
  1502.             *tp = '\0';
  1503.             break;
  1504.             } else tp++, j++;
  1505.         }
  1506.         if (!xxstrcmp(lp,s,(y > j) ? y : j)) { /* Caseless compare */
  1507.             x = 1;        /* Got it */
  1508.             break;        /* done. */
  1509.         }
  1510.         }
  1511.         if (x == 0) {        /* If not found, print message */
  1512.         debug(F101,"goto failed at cmdlvl","",cmdlvl);
  1513.         if (!popclvl()) {    /* pop up to next higher level */
  1514.             printf("?Label '%s' not found\n",s);    /* if none */
  1515.             return(0);        /* quit */
  1516.         } else continue;    /* otherwise look again */
  1517.         }
  1518.         return(x);            /* Send back return code */
  1519.     }
  1520.     }
  1521.     printf("?Stack problem in GOTO %s\n",s); /* Shouldn't see this */
  1522.     return(0);
  1523. }
  1524. #endif /* NOSPL */
  1525.  
  1526. #ifndef NOSPL
  1527. /* Finish parsing and do the IF, XIF, and WHILE commands */
  1528.  
  1529. int
  1530. doif(cx) int cx; {
  1531.     int x, y, z; char *s, *p;
  1532.  
  1533.     not = 0;                /* Flag for whether "NOT" was seen */
  1534.     z = 0;                /* Initial IF condition */
  1535.     ifargs = 0;                /* Count of IF condition words */
  1536.  
  1537. ifagain:
  1538.     if ((ifc = cmkey(iftab,nif,"","",xxstring)) < 0) { /* If what?... */
  1539.     if (ifc == -3) {
  1540.         printf("?Condition required\n");
  1541.         return(-9);
  1542.     } else return(ifc);
  1543.     }
  1544.     switch (ifc) {            /* set z = 1 for true, 0 for false */
  1545.       case XXIFNO:            /* IF NOT */
  1546.     not ^= 1;            /* So NOT NOT NOT ... will work */
  1547.     ifargs++;
  1548.     goto ifagain;
  1549.       case XXIFSU:            /* IF SUCCESS */
  1550.     z = ( success != 0 );
  1551.     debug(F101,"if success","",z);
  1552.     ifargs += 1;
  1553.     break;
  1554.       case XXIFFA:            /* IF FAILURE */
  1555.     z = ( success == 0 );
  1556.     debug(F101,"if failure","",z);
  1557.     ifargs += 1;
  1558.     break;
  1559.       case XXIFDE:            /* IF DEFINED */
  1560.     if ((x = cmfld("Macro or variable name","",&s,NULL)) < 0) {
  1561.         if (x == -3) return(-2);
  1562.         else return(x);
  1563.     }
  1564. #ifdef COMMENT
  1565.     strcpy(line,s);            /* Make a copy */
  1566.         if ((int)strlen(line) < 1) return(-2);
  1567.     lp = line;
  1568.     if (line[0] == CMDQ && (line[1] == '%' || line[1] == '&')) lp++;
  1569.     if (*lp == '%')    {        /* Is it a variable? */
  1570.         x = *(lp + 1);        /* Fold case */
  1571.         if (isupper(x)) *(lp + 1) = tolower(x);
  1572.         if (x >= '0' && x <= '9' && maclvl > -1) /* Digit is macro arg */
  1573.           z = ( (m_arg[maclvl][x - '0'] != (char *)0)
  1574.            && (int)strlen(m_arg[maclvl][x - '0']) != 0);
  1575.         else            /* Otherwise it's a global variable */
  1576.           z = ( (g_var[x] != (char *)0)
  1577.            &&  (int)strlen(g_var[x]) != 0 );
  1578.     } else if (*lp == '&') {    /* Array reference */
  1579.         int cc, nn;
  1580.         if (arraynam(lp,&cc,&nn) < 0)
  1581.           z = 0;
  1582.         else z = (arrayval(cc,nn) == NULL ? 0 : 1);
  1583.     }
  1584. #else
  1585.         if ((int)strlen(s) < 1) return(-2);
  1586.     z = 0;                /* Assume failure. */
  1587.     if (*s == CMDQ) {        /* Object begins with backslash. */
  1588.         char c;
  1589.         c = s[1];            /* Character following backslash */
  1590.         if (c) {
  1591.         c = islower(c) ? toupper(c) : c;
  1592.         if (c == '%' ||        /* Simple variable */
  1593.             c == '&' ||        /* Array element */
  1594.             c == '$' ||        /* Environment variable */
  1595.             c == 'V' ||        /* Builtin named variable */
  1596.             c == 'M' ||        /* Macro name */
  1597.             c == 'F') {        /* Builtin function */
  1598.             int t;        /* Let xxstring() evaluate it */
  1599.             t = LINBUFSIZ-1;    /* This lets us test \v(xxx) */
  1600.             lp = line;        /* and even \f...(xxx) */
  1601.             xxstring(s,&lp,&t);    /* Evaluate it, whatever it is. */
  1602.             t = strlen(line);    /* Get its length. */
  1603.             debug(F111,"IF DEF",line,t);
  1604.             z = t > 0;        /* If length > 0, it's defined */
  1605.         }
  1606.         }
  1607.     }
  1608. #endif /* COMMENT */
  1609.     else {            /* Otherwise it's a macro name */
  1610.         z = ( mxlook(mactab,s,nmac) > -1 ); /* Look for exact match */
  1611.     }
  1612.     debug(F111,"if defined",s,z);
  1613.     ifargs += 2;
  1614.     break;
  1615.  
  1616.       case XXIFBG:            /* IF BACKGROUND */
  1617.       case XXIFFG:            /* IF FOREGROUND */    
  1618.     bgchk();            /* Check background status */
  1619.     if (ifc == XXIFFG)        /* Foreground */
  1620.       z = pflag ? 1 : 0;
  1621.         else z = pflag ? 0 : 1;        /* Background */
  1622.     ifargs += 1;
  1623.     break;
  1624.  
  1625.       case XXIFCO:            /* IF COUNT */
  1626.     z = ( --count[cmdlvl] > 0 );
  1627.     if (cx == XXWHI) count[cmdlvl] += 2; /* Don't ask... */
  1628.     debug(F101,"if count","",z);
  1629.     ifargs += 1;
  1630.     break;
  1631.  
  1632.       case XXIFEX:            /* IF EXIST */
  1633.     if ((x = cmfld("File","",&s,xxstring)) < 0) {
  1634.         if (x == -3) {
  1635.         printf("?Filename required\n");
  1636.         return(-9);
  1637.         } else return(x);
  1638.     }
  1639.     z = ( zchki(s) > -1L );
  1640.     debug(F101,"if exist","",z);
  1641.     ifargs += 2;
  1642.     break;
  1643.  
  1644.       case XXIFEQ:             /* IF EQUAL (string comparison) */
  1645.       case XXIFLL:            /* IF Lexically Less Than */
  1646.       case XXIFLG:            /* If Lexically Greater Than */
  1647.     if ((x = cmfld("first word or variable name","",&s,xxstring)) < 0) {
  1648.         if (x == -3) {
  1649.         printf("?Text required\n");
  1650.         return(-9);
  1651.         } else return(x);
  1652.     }
  1653.     x = (int)strlen(s);
  1654.     if (x > LINBUFSIZ-1) {
  1655.         printf("?IF: strings too long\n");
  1656.         return(-2);
  1657.     }
  1658.     lp = line;            /* lp points to first string */
  1659.     strcpy(lp,s);
  1660.     if ((y = cmfld("second word or variable name","",&s,xxstring)) < 0) {
  1661.         if (y == -3) {
  1662.         printf("?Text required\n");
  1663.         return(-9);
  1664.         } else return(y);
  1665.     }
  1666.     y = (int)strlen(s);
  1667.     if (x + y + 2 > LINBUFSIZ) {
  1668.         printf("?IF: strings too long\n");
  1669.         return(-2);
  1670.     }
  1671.     tp = lp + y + 2;        /* tp points to second string */
  1672.     strcpy(tp,s);
  1673.     if (inpcas[cmdlvl])        /* INPUT CASE OBSERVE */
  1674.       x = strcmp(lp,tp);
  1675.     else                /* INPUT CASE IGNORE */
  1676.       x = xxstrcmp(lp,tp,(y > x) ? y : x); /* Use longest length */
  1677.     debug(F101,"IF comparison","",x);
  1678.     switch (ifc) {
  1679.       case XXIFEQ:             /* IF EQUAL (string comparison) */
  1680.         z = (x == 0);
  1681.         break;
  1682.       case XXIFLL:            /* IF Lexically Less Than */
  1683.         z = (x < 0);
  1684.         break;
  1685.       case XXIFLG:            /* If Lexically Greater Than */
  1686.         z = (x > 0);
  1687.         break;
  1688.     }
  1689.     ifargs += 3;
  1690.     break;
  1691.  
  1692.       case XXIFAE:            /* IF (arithmetically) = */
  1693.       case XXIFLT:            /* IF (arithmetically) < */
  1694.       case XXIFGT: {            /* IF (arithmetically) > */
  1695.     /* Really should use longs here... */
  1696.     /* But cmnum parses ints. */
  1697.     int n1, n2;
  1698.     x = cmfld("first number or variable name","",&s,xxstring);
  1699.     if (x == -3) {
  1700.         printf("?Quantity required\n");
  1701.         return(-9);
  1702.     }
  1703.     if (x < 0) return(x);
  1704.     debug(F101,"xxifgt cmfld","",x);
  1705.     lp = line;
  1706.     strcpy(lp,s);
  1707.     debug(F110,"xxifgt exp1",lp,0);
  1708.     if (!xxstrcmp(lp,"count",5)) {
  1709.         n1 = count[cmdlvl];
  1710.     } else if (!xxstrcmp(lp,"version",7)) {
  1711.         n1 = (int) vernum;
  1712.     } else if (!xxstrcmp(lp,"argc",4)) {
  1713.         n1 = (int) macargc[maclvl];
  1714.     } else {
  1715.         if (!chknum(lp)) return(-2);
  1716.         n1 = atoi(lp);
  1717.     }
  1718.     y = cmfld("second number or variable name","",&s,xxstring);
  1719.     if (y == -3) {
  1720.         printf("?Quantity required\n");
  1721.         return(-9);
  1722.     }
  1723.     if (y < 0) return(y);
  1724.         if ((int)strlen(s) < 1) return(-2);
  1725.     x = (int)strlen(lp);
  1726.     tp = line + x + 2;
  1727.     strcpy(tp,s);
  1728.     debug(F110,"xxifgt exp2",tp,0);
  1729.     if (!xxstrcmp(tp,"count",5)) {
  1730.         n2 = count[cmdlvl];
  1731.     } else if (!xxstrcmp(tp,"version",7)) {
  1732.         n2 = (int) vernum;
  1733.     } else if (!xxstrcmp(tp,"argc",4)) {
  1734.         n2 = (int) macargc[maclvl];
  1735.     } else {
  1736.         if (!chknum(tp)) return(-2);
  1737.         n2 = atoi(tp);
  1738.     }
  1739.     debug(F101,"xxifft ifc","",ifc);
  1740.     z = ((n1 <  n2 && ifc == XXIFLT)
  1741.       || (n1 == n2 && ifc == XXIFAE)
  1742.       || (n1 >  n2 && ifc == XXIFGT));
  1743.     debug(F101,"xxifft n1","",n1);
  1744.     debug(F101,"xxifft n2","",n2);
  1745.     debug(F101,"xxifft z","",z);
  1746.     ifargs += 3;
  1747.     break; }
  1748.  
  1749.       case XXIFNU:            /* IF NUMERIC */
  1750.     x = cmfld("variable name or constant","",&s,xxstring);
  1751.     if (x == -3) {
  1752.         printf("?Quantity required\n");
  1753.         return(-9);
  1754.     }
  1755.     if (x < 0) return(x);
  1756.     debug(F111,"xxifnu cmfld",s,x);
  1757.     lp = line;
  1758.     strcpy(lp,s);
  1759.     debug(F110,"xxifnu quantity",lp,0);
  1760.         z = chknum(lp);
  1761.         debug(F101,"xxifnu chknum","",z);
  1762.     ifargs += 2;
  1763.     break;
  1764.  
  1765.       default:                /* Shouldn't happen */
  1766.     return(-2);
  1767.     }
  1768.     if (not) z = !z;            /* Handle NOT here for both IF & XIF */
  1769.  
  1770.     switch (cx) {            /* Separate handling for IF and XIF */
  1771.  
  1772.       case XXIF:            /* This is IF... */
  1773.     ifcmd[cmdlvl] = 1;        /* We just completed an IF command */
  1774.     if (z) {            /* Condition is true */
  1775.         iftest[cmdlvl] = 1;        /* Remember that IF succeeded */
  1776.         if (maclvl > -1) {        /* In macro, */
  1777.         pushcmd();        /* save rest of command. */
  1778.         } else if (tlevel > -1) {    /* In take file, */
  1779.         debug(F100, "doif: pushing command", "", 0);
  1780.         pushcmd();        /* save rest of command. */
  1781.         } else {            /* If interactive, */
  1782.         cmini(ckxech);        /* just start a new command */
  1783.         printf("\n");        /* (like in MS-DOS Kermit) */
  1784.         if (pflag) prompt(xxstring);
  1785.         }
  1786.     } else {            /* Condition is false */
  1787.         iftest[cmdlvl] = 0;        /* Remember command failed. */
  1788.         if ((y = cmtxt("command to be ignored","",&s,NULL)) < 0)
  1789.           return(y);        /* Gobble up rest of line */
  1790.     }
  1791.     return(0);
  1792.  
  1793.       case XXIFX: {            /* This is XIF (Extended IF) */
  1794.       char *p;
  1795.       char e[5];
  1796.       int i;
  1797.       if ((y = cmtxt("Object command","",&s,NULL)) < 0)
  1798.         return(y);            /* Get object command. */
  1799.       p = s;
  1800.       lp = line;
  1801.       if (litcmd(&p,&lp) < 0) {    /* Insert quotes in THEN-part */
  1802.           return(-2);
  1803.       }
  1804.       if (!z) {            /* Use ELSE-part, if any */
  1805.           lp = line;        /* Write over THEN part. */
  1806.           *lp = NUL;
  1807.           while (*p == SP) p++;    /* Strip trailing spaces */
  1808.           if (*p) {            /* At end? */
  1809.           for (i = 0; i < 4; i++) e[i] = *p++; /* No, check for ELSE */
  1810.           if (xxstrcmp(e,"else",4)) return(-2);    /* No, syntax error */
  1811.           if (litcmd(&p,&lp) < 0) { /* Insert quotes */
  1812.               return(-2);
  1813.           }
  1814.           while (*p == SP) p++;    /* Strip trailing spaces */
  1815.           if (*p) return(-2);    /* Should be nothing here. */
  1816.           }
  1817.       }
  1818.       if (line[0]) {
  1819.           x = mlook(mactab,"_xif",nmac); /* get index of "_xif" macro. */
  1820.           if (x < 0) {            /* Not there? */
  1821.           addmmac("_xif",xif_def);    /* Put it back. */
  1822.           if (mlook(mactab,"_xif",nmac) < 0) { /* Look it up again. */
  1823.               printf("?XIF macro gone!\n");
  1824.               return(success = 0);
  1825.           }
  1826.           }
  1827.           dodo(x,line);        /* Do the XIF macro */
  1828.       }
  1829.       return(0);
  1830.       }
  1831.       case XXWHI: {            /* WHILE Command */
  1832.       p = cmdbuf;            /* Capture IF condition */
  1833.       ifcond[0] = NUL;        /* from command buffer */
  1834.       while (*p == SP) p++;
  1835.       while (*p != SP) p++;
  1836.       ifcp = ifcond;
  1837.       strcpy(ifcp,"{ \\flit(if not ");
  1838.       ifcp += (int)strlen(ifcp);
  1839.       while (*p != '{' && *p != NUL) *ifcp++ = *p++;
  1840.       p = " goto bot) } ";
  1841.       while (*ifcp++ = *p++) ;
  1842.       debug(F110,"WHILE cmd",ifcond,0);
  1843.  
  1844.       if ((y = cmtxt("Object command","",&s,NULL)) < 0)
  1845.         return(y);            /* Get object command. */
  1846.       p = s;
  1847.       lp = line;
  1848.       if (litcmd(&p,&lp) < 0) {    /* Insert quotes in object command */
  1849.           return(-2);
  1850.       }
  1851.       debug(F110,"WHILE body",line,0);
  1852.       if (line[0]) {
  1853.           char *p;
  1854.           x = mlook(mactab,"_while",nmac); /* index of "_while" macro. */
  1855.           if (x < 0) {        /* Not there? */
  1856.           addmmac("_while",whil_def); /* Put it back. */
  1857.           if (mlook(mactab,"_while",nmac) < 0) { /* Look it up again */
  1858.               printf("?WHILE macro definition gone!\n");
  1859.               return(success = 0);
  1860.           }
  1861.           }
  1862.           p = malloc((int)strlen(ifcond) + (int)strlen(line) + 2);
  1863.           if (p) {
  1864.           strcpy(p,ifcond);
  1865.           strcat(p,line);
  1866.           debug(F110,"WHILE dodo",p,0);
  1867.           dodo(x,p);
  1868.           free(p);
  1869.           } else {
  1870.           printf("?Can't allocate storage for WHILE command");
  1871.           return(success = 0);
  1872.           }
  1873.       }
  1874.       return(0);
  1875.       }
  1876.       default:
  1877.     return(-2);
  1878.     }
  1879. }
  1880. #endif /* NOSPL */
  1881.  
  1882. /* Set up a TAKE command file */
  1883.  
  1884. int
  1885. dotake(s) char *s; {
  1886.     if ((tfile[++tlevel] = fopen(s,"r")) == NULL) {
  1887.     perror(s);
  1888.     debug(F110,"Failure to open",s,0);
  1889.     success = 0;
  1890.     tlevel--;
  1891.     } else {
  1892. #ifdef VMS
  1893.     conres();            /* So Ctrl-C will work */
  1894. #endif /* VMS */
  1895. #ifndef NOSPL
  1896.     cmdlvl++;            /* Entering a new command level */
  1897.     if (cmdlvl > CMDSTKL) {
  1898.         cmdlvl--;
  1899.         printf("?TAKE files and/or DO commands nested too deeply\n");
  1900.         return(success = 0);
  1901.     }
  1902.     if (tfnam[tlevel]) free(tfnam[tlevel]);    /* Copy the filename */
  1903.     if (tfnam[tlevel] = malloc(strlen(s) + 1))
  1904.       strcpy(tfnam[tlevel],s);
  1905.     ifcmd[cmdlvl] = 0;        /* Set variables for this cmd file */
  1906.     iftest[cmdlvl] = 0;
  1907.     count[cmdlvl]  = count[cmdlvl-1];  /* Inherit this */
  1908.     intime[cmdlvl] = intime[cmdlvl-1]; /* Inherit this */
  1909.     inpcas[cmdlvl] = inpcas[cmdlvl-1]; /* Inherit this */
  1910.     takerr[cmdlvl] = takerr[cmdlvl-1]; /* Inherit this */
  1911.     merror[cmdlvl] = merror[cmdlvl-1]; /* Inherit this */
  1912.     cmdstk[cmdlvl].src = CMD_TF;    /* Say we're in a TAKE file */
  1913.     cmdstk[cmdlvl].lvl = tlevel;    /* nested at this level */
  1914. #else
  1915.     takerr[tlevel] = takerr[tlevel-1]; /* Inherit this */
  1916. #endif /* NOSPL */
  1917.     }
  1918.     return(1);
  1919. }
  1920. #endif /* NOICP */
  1921.